package com.example.a2205douyin.live;

import androidx.lifecycle.MutableLiveData;

import com.example.a2205douyin.baseMVVM.viewmodel.BaseViewModel;
import com.example.a2205douyin.entity.GiftEntity;
import com.example.a2205douyin.entity.ResultEntity;
import com.example.a2205douyin.entity.VideoEntity;
import com.google.gson.Gson;

import java.util.HashMap;
import java.util.Map;

import okhttp3.MediaType;
import okhttp3.RequestBody;

public class LiveViewModel extends BaseViewModel<LiveRepo> {
    @Override
    protected LiveRepo createRepo() {
        return new LiveRepo();
    }
    //关注
    public MutableLiveData<ResultEntity> guanSucc = new MutableLiveData<>();
    public MutableLiveData<String> guanFail = new MutableLiveData<>();
    public void guanzhu(String name){
        Map<String,String> map = new HashMap<>();
        map.put("authname",name);
        String s = new Gson().toJson(map);
        RequestBody body = RequestBody.create(MediaType.parse("application/json;charset=UTF-8"),s);
        repo.guanzhu(body,guanSucc,guanFail);
    }
    //取消关注
    public MutableLiveData<ResultEntity> noguanSucc = new MutableLiveData<>();
    public MutableLiveData<String> noguanFail = new MutableLiveData<>();
    public void noguanzhu(String name){
        Map<String,String> map = new HashMap<>();
        map.put("authname",name);
        String s = new Gson().toJson(map);
        RequestBody body = RequestBody.create(MediaType.parse("application/json;charset=UTF-8"),s);
        repo.noguanzhu(body,noguanSucc,noguanFail);
    }

    public MutableLiveData<GiftEntity> giftSucc = new MutableLiveData<>();
    public MutableLiveData<String> giftFail = new MutableLiveData<>();
    public void gift(){
        repo.gift(giftSucc,giftFail);
    }

    //分页查询
    public MutableLiveData<VideoEntity> videoSuccess = new MutableLiveData<>();
    public MutableLiveData<String> videoFail = new MutableLiveData<>();
    public void video(int page,int size){
        repo.video(page,size,videoSuccess,videoFail);
    }
}
